// pagesBusiness/pages/myregister/index.js
const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [], //挂号列表
    pageParams: {
      pageSize: 10,
      totalPages: 0,
      pageNo: 1,
    },
    tmpMsgShow: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    console.log("onshow");
    if (this.data.list.length <= 0) {
      this.getDataList();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.resetQuery();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.pageParams.totalPages > this.data.pageParams.pageNo) {
      this.data.pageParams.pageNo = this.data.pageParams.pageNo + 1;
      this.setData({
        pageParams: this.data.pageParams,
      }) 
      this.getDataList();
    } else {
      wx.showToast({
        title: '没有更多了',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  resetQuery: function () {
    this.data.pageParams.pageNo = 1;
    let params = this.data.pageParams;
    this.setData({
      list: [],
      pageParams: params,
    })
    this.getDataList();

  },


  getDataList: function () {
    let that = this;
    let pageParams = that.data.pageParams;
    wx.showLoading({
      title: '加载中...',
    })
    util.request(api.orderList, that.data.pageParams).then(res => {
      wx.hideLoading();
      if (res.errno == 0) {
        console.log(res.data)
        pageParams.totalPages = res.data.pages;
        pageParams.pageNo = res.data.page;
        that.setData({
          pageParams: pageParams,
          list: that.data.list.concat(res.data.list)
        })
      }
    }).catch(err => {
      wx.hideLoading();
    });
  },

  

  /**
   * 进入问诊
   * @param {} e 
   */
  goDoctor(e) {
    let id = e.currentTarget.dataset.id;
    /** 
    wx.navigateTo({
      url: `/pages/reportRisk/index?paperId=${id}`,
    })
    */

    wx.redirectTo({
      url: `/pages/riskIndex/index?paperId=${id}`,
    })

  },

  pdfView(e) {
    let url = e.currentTarget.dataset.url;
    console.log(url);
    wx.navigateTo({
      url: `/pages/webview/pdfView/index?url=${url}`,
    })

  },

  goDetail(e) {
    let id = e.currentTarget.dataset.id;
    console.log(id);
    wx.navigateTo({
      url: `/pages/checkRecordDetail/index?id=${id}`,
    })

  },

  readResult(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/webview/humanResult/index?paperId=${id}`,
    })
  },
})